package com.zzy.clone;

import java.util.HashMap;
/**
 * Collection clone的方法是深克隆
 * @author eason
 *
 */
public class MapClone {

	public static void main(String[] args) {
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(1);
		list.add(2);
		
		ArrayList<Integer> listClone = (ArrayList<Integer>) list.clone();
		listClone.add(3);
		
		printList(list);
		System.out.println("==");
		printList(listClone);
		
		System.out.println("==========================");
		
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		map.put(1, 1);
		
		HashMap<Integer, Integer> mapClone = (HashMap<Integer, Integer>) map.clone();
		mapClone.put(1, 2);
		
		System.out.println(map.get(1));
		System.out.println("==");
		System.out.println(mapClone.get(1));
		
		
	}
	
	private static void printList(ArrayList<Integer> list) {
		for(Integer i : list){
			System.out.println(i);
		}
	}

}
